package com.android.kmobi.locket.receiver;

import com.android.kmobi.locket.mpcontrol.MpControl;
import com.android.kmobi.locket.ui.MainActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class LocketReceiver extends  BroadcastReceiver {
	
	private boolean isStaticReceiver = true;
	
	public void setIsStaticReceiver(boolean bool) {
		isStaticReceiver = bool;
	}

	private void startActivity(Context context,String action) {
		Intent startIntent = new Intent(action);
		//startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
		startIntent.setClass(context, MainActivity.class);
		startIntent.putExtra("from", "LocketReceiver");
		context.startActivity(startIntent);
	}
	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		if(context!=null&&intent!=null)
		{
			MpControl.getInstance(context).init();
			String action = intent.getAction();
			if(action!=null)
			{
				if(action.equals(Intent.ACTION_SCREEN_ON))//屏亮
				{
					Log.e("muge","LocketReceiver 屏亮: ACTION_SCREEN_ON="+action+(isStaticReceiver?" 静态广播接收者！":"动态广播接收者"));
					startActivity(context,action);
				}
				else if(action.equals(Intent.ACTION_USER_PRESENT))//用户解锁
				{
					Log.e("muge","LocketReceiver 用户解锁:ACTION_USER_PRESENT="+action+(isStaticReceiver?" 静态广播接收者！":"动态广播接收者"));
					startActivity(context,action);
				}
				else if(action.equals(Intent.ACTION_SCREEN_OFF))//屏暗
				{
					Log.e("muge","LocketReceiver 屏暗:ACTION_SCREEN_OFF="+action+(isStaticReceiver?" 静态广播接收者！":"动态广播接收者"));
				}
				else
				{
					Log.e("muge","LocketReceiver 闹钟唤醒:CLOCK_WAKEUP_ACTION="+action+(isStaticReceiver?" 静态广播接收者！":"动态广播接收者"));
				}
			}
		}
		
	}

}
